package com.compty.paint.manager;

import java.util.Date;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.compty.core.hibernate.HibernateEntityDao;
import com.compty.core.page.Page;
import com.compty.paint.domain.PromotionDetail;
import com.compty.security.domain.User;

/**
 * @Todo:推广记录 Manager
 * @author: 朱庆辉
 * @CreateTime:2012-4-16 上午08:52:57
 */
public class PromotionDetailManager  extends HibernateEntityDao<PromotionDetail>{

	/**
	 *@Todo:分页查询推广基本信息
	 *@author:朱庆辉
	 *@CreateTime:2012-4-16 上午08:57:31
	 * @param curPage 当前页码
	 * @param pageSize 页面大小 
	 * @param userInfo 当前登录用户
	 * @param startDate 开始日期
	 * @param endDate  截止日期
	 * @param filterTxt 字段名称
	 * @param filterValue 字段值
	 * @return
	 */
	public Page queryForPage(Integer curPage, Integer pageSize, User userInfo,
			Date startDate, Date endDate, String filterTxt, String filterValue) {
		// TODO Auto-generated method stub
		 Criteria criteria =  super.createCriteria();
		  
	        criteria.addOrder(Order.desc("id"));
	        
	        if(userInfo!= null && "0".equals(userInfo.getAdministratorFlag())){
	        	  criteria = criteria.add(Restrictions.eq("user", userInfo));
	        }
	        
	        if(startDate != null){
	        	 criteria = criteria.add(Restrictions.ge("createTime", startDate));
	        }
	        
	        if(endDate != null){
	        	 criteria = criteria.add(Restrictions.lt("createTime", endDate));
	        }

	        if ((filterTxt != null) && (filterValue != null)&& (!filterTxt.equals("")) && (!filterValue.equals(""))) {
	            criteria = criteria.add(Restrictions.like(filterTxt,
	                        "%" + filterValue + "%"));
	        }
	        
	        Page page = super.pagedQuery(criteria, curPage, pageSize);
	        
	        return page;
	}

}
